<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/**
<span class='line'>  2</span>  * @fileOverview js-itm: a Javascript library for converting between Israel Transverse Mercator (ITM) and GPS (WGS84) coordinates.&lt;p>
<span class='line'>  3</span>  * &lt;a href="http://code.google.com/p/js-itm/">http://code.google.com/p/js-itm/&lt;/a>
<span class='line'>  4</span>  * @author Udi Oron (udioron at g mail dot com)
<span class='line'>  5</span>  * @author forked from &lt;a href="http://www.nearby.org.uk/tests/GeoTools.html">GeoTools&lt;/a> by Paul Dixon
<span class='line'>  6</span>  * @copyright &lt;a href="http://www.gnu.org/copyleft/gpl.html">GPL&lt;/a>
<span class='line'>  7</span>  * @version 0.1.1 ($Rev: 8 $ $Date: 2008-12-14 21:29:39 +0200 (Sun, 14 Dec 2008) $)
<span class='line'>  8</span>  */</span><span class="WHIT">
<span class='line'>  9</span> 
<span class='line'> 10</span> </span><span class="COMM">/**
<span class='line'> 11</span>  * Parent namespace for the entire library
<span class='line'> 12</span>  * @namespace
<span class='line'> 13</span>  */</span><span class="WHIT">
<span class='line'> 14</span> </span><span class="NAME">JSITM</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 15</span> 
<span class='line'> 16</span> </span><span class="COMM">/**************************************************************/</span><span class="WHIT">
<span class='line'> 17</span> 
<span class='line'> 18</span> </span><span class="COMM">/**
<span class='line'> 19</span>  * Creates a new LatLng.
<span class='line'> 20</span>  * 
<span class='line'> 21</span>  * @class holds geographic coordinates measured in degrees.&lt;br/>
<span class='line'> 22</span>  * &lt;a href="http://en.wikipedia.org/wiki/Geographic_coordinate">http://en.wikipedia.org/wiki/Geographic_coordinate&lt;/a>
<span class='line'> 23</span>  *
<span class='line'> 24</span>  * @constructor
<span class='line'> 25</span>  * @param {Number} lat latitude in degrees ( http://en.wikipedia.org/wiki/Latitude )
<span class='line'> 26</span>  * @param {Number} lng longtitude in degrees ( http://en.wikipedia.org/wiki/Longitude )
<span class='line'> 27</span>  * @param {Number} alt altitude in meters above the uesd geoid surface - this was not used or tested - please keep this always 0.
<span class='line'> 28</span>  * @param {Number} precision number of digits after the decimal point, used in printout. see toString().
<span class='line'> 29</span>  */</span><span class="WHIT">
<span class='line'> 30</span> </span><span class="NAME">JSITM.LatLng</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">lat</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">lng</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">alt</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">precision</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 31</span>     </span><span class="NAME">this.lat</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">lat</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 32</span>     </span><span class="NAME">this.lng</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">lng</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 33</span>     </span><span class="NAME">this.alt</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">alt</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 34</span>     </span><span class="NAME">this.precision</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">precision</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NUMB">5</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 35</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 36</span> 
<span class='line'> 37</span> </span><span class="COMM">/**
<span class='line'> 38</span>  * Returns Latlng as string, using the defined preccision
<span class='line'> 39</span>  * @return {String}
<span class='line'> 40</span>  */</span><span class="WHIT">
<span class='line'> 41</span> </span><span class="NAME">JSITM.LatLng.prototype.toString</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 42</span> 
<span class='line'> 43</span>     </span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">round</span><span class="PUNC">(</span><span class="NAME">n</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">precision</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 44</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">m</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NUMB">10</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">precision</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 45</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">Math.round</span><span class="PUNC">(</span><span class="NAME">n</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">m</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">m</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 46</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 47</span>     
<span class='line'> 48</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">round</span><span class="PUNC">(</span><span class="NAME">this.lat</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this.precision</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">" "</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">round</span><span class="PUNC">(</span><span class="NAME">this.lng</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this.precision</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 49</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 50</span> 
<span class='line'> 51</span> </span><span class="COMM">/**
<span class='line'> 52</span>  * Creates a new LatLng by converting coordinates from a source ellipsoid to a target one. &lt;p>
<span class='line'> 53</span>  * This process involves:&lt;p>
<span class='line'> 54</span>  *   1. converting the angular latlng to cartesian coordinates using latLngToPoint()&lt;p>
<span class='line'> 55</span>  *   2. translating the XYZ coordinates using a translation, with special values supplied to this translation.&lt;p>
<span class='line'> 56</span>  *   3. converting the translated XYZ coords back to a new angular LatLng&lt;p>
<span class='line'> 57</span>  *&lt;p>
<span class='line'> 58</span>  *  for example refer to {@link JSITM.itm2gps}
<span class='line'> 59</span>  *
<span class='line'> 60</span>  * @param {JSITM.Ellipsoid} from source elli
<span class='line'> 61</span>  * @param {JSITM.Ellipsoid} to
<span class='line'> 62</span>  * @param {JSITM.Translation} translation
<span class='line'> 63</span>  * @return {JSITM.LatLng}
<span class='line'> 64</span>  */</span><span class="WHIT">
<span class='line'> 65</span> </span><span class="NAME">JSITM.LatLng.prototype.convertGrid</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">from</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">to</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">translation</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 66</span> 
<span class='line'> 67</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">point</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">from.latLngToPoint</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 68</span>     
<span class='line'> 69</span>     </span><span class="COMM">//removed 7 point Helmert translation (not needed in Israel's grids)</span><span class="WHIT">
<span class='line'> 70</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">translated</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">translation.translate</span><span class="PUNC">(</span><span class="NAME">point</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 71</span>     
<span class='line'> 72</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">to.pointToLatLng</span><span class="PUNC">(</span><span class="NAME">translated</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 73</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 74</span> 
<span class='line'> 75</span> </span><span class="COMM">/**
<span class='line'> 76</span>  * Parses latitude and longtitude in a string into a new Latlng
<span class='line'> 77</span>  * @param {String} s
<span class='line'> 78</span>  * @return {JSITM.LatLng}
<span class='line'> 79</span>  */</span><span class="WHIT">
<span class='line'> 80</span> </span><span class="NAME">JSITM.latlngFromString</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 81</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">pattern</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">RegExp</span><span class="PUNC">(</span><span class="STRN">"^(-?\\d+(?:\\.\\d*)?)(?:(?:\\s*[:,]?\\s*)|\\s+)(-?\\d+(?:\\.\\d*)?)$"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"i"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 82</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">latlng</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.match</span><span class="PUNC">(</span><span class="NAME">pattern</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 83</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">latlng</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 84</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">lat</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parseFloat</span><span class="PUNC">(</span><span class="NAME">latlng</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">10</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 85</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">lng</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parseFloat</span><span class="PUNC">(</span><span class="NAME">latlng</span><span class="PUNC">[</span><span class="NUMB">2</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">10</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 86</span>         </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">JSITM.LatLng</span><span class="PUNC">(</span><span class="NAME">lat</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">lng</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 87</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 88</span> 
<span class='line'> 89</span> 	</span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="STRN">"could not parse latlng"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 90</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 91</span> 
<span class='line'> 92</span> </span><span class="COMM">/**************************************************************/</span><span class="WHIT">
<span class='line'> 93</span> 
<span class='line'> 94</span> </span><span class="COMM">/**
<span class='line'> 95</span>  * Creates a new Point.
<span class='line'> 96</span>  * @class holds 2D/3D cartesian coordinates.
<span class='line'> 97</span>  * 
<span class='line'> 98</span>  * @constructor
<span class='line'> 99</span>  * @param {Number} x
<span class='line'>100</span>  * @param {Number} y
<span class='line'>101</span>  * @param {Number} z
<span class='line'>102</span>  * @return {JSITM.Point}
<span class='line'>103</span>  */</span><span class="WHIT">
<span class='line'>104</span> </span><span class="NAME">JSITM.Point</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">x</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">y</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">z</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>105</span>     </span><span class="NAME">this.y</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">y</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>106</span>     </span><span class="NAME">this.x</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">x</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>107</span>     </span><span class="NAME">this.z</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">z</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>108</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>109</span> 
<span class='line'>110</span> </span><span class="COMM">/**
<span class='line'>111</span>  * Returns a string containing the Point coordinates in meters
<span class='line'>112</span>  * @return {String}
<span class='line'>113</span>  */</span><span class="WHIT">
<span class='line'>114</span> </span><span class="NAME">JSITM.Point.prototype.toString</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>115</span> 	
<span class='line'>116</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">Math.round</span><span class="PUNC">(</span><span class="NAME">this.x</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">" "</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">Math.round</span><span class="PUNC">(</span><span class="NAME">this.y</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>117</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>118</span> 
<span class='line'>119</span> 
<span class='line'>120</span> </span><span class="COMM">/**************************************************************/</span><span class="WHIT">
<span class='line'>121</span> 
<span class='line'>122</span> </span><span class="COMM">/**
<span class='line'>123</span>  * Creates a new Translation.
<span class='line'>124</span>  * &lt;p>
<span class='line'>125</span>  * (Helmert translation were depracted since they are not used in the ITM - feel free to add them back from geotools if you need them! :-) )
<span class='line'>126</span>  * 
<span class='line'>127</span>  * @constructor 
<span class='line'>128</span>  * @param {Number} dx
<span class='line'>129</span>  * @param {Number} dy
<span class='line'>130</span>  * @param {Number} dz
<span class='line'>131</span>  */</span><span class="WHIT">
<span class='line'>132</span> </span><span class="NAME">JSITM.Translation</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">dx</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">dy</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">dz</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>133</span>     </span><span class="NAME">this.dx</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">dx</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>134</span>     </span><span class="NAME">this.dy</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">dy</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>135</span>     </span><span class="NAME">this.dz</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">dz</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>136</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>137</span> 
<span class='line'>138</span> </span><span class="COMM">/**
<span class='line'>139</span>  * Return a new translated Point. (Original point kept intact)
<span class='line'>140</span>  *
<span class='line'>141</span>  * @param {JSITM.Point} point original point.
<span class='line'>142</span>  * @return {JSITM.Point}
<span class='line'>143</span>  */</span><span class="WHIT">
<span class='line'>144</span> </span><span class="NAME">JSITM.Translation.prototype.translate</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">point</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>145</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">JSITM.Point</span><span class="PUNC">(</span><span class="NAME">point.x</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">this.dx</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">point.y</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">this.dy</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">point.z</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">this.dz</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>146</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>147</span> 
<span class='line'>148</span> </span><span class="COMM">/**
<span class='line'>149</span>  * Returns an new Translation with inverse values.
<span class='line'>150</span>  * @return {JSITM.Translation}
<span class='line'>151</span>  */</span><span class="WHIT">
<span class='line'>152</span> </span><span class="NAME">JSITM.Translation.prototype.inverse</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>153</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">JSITM.Translation</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NAME">this.dx</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NAME">this.dy</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NAME">this.dz</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>154</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>155</span> 
<span class='line'>156</span> </span><span class="COMM">/**************************************************************/</span><span class="WHIT">
<span class='line'>157</span> 
<span class='line'>158</span> </span><span class="COMM">/**
<span class='line'>159</span>  * Creates a new Ellipsoid.&lt;p>
<span class='line'>160</span>  * for more info see &lt;a href="http://en.wikipedia.org/wiki/Reference_ellipsoid">http://en.wikipedia.org/wiki/Reference_ellipsoid&lt;/a>
<span class='line'>161</span>  *
<span class='line'>162</span>  * @constructor
<span class='line'>163</span>  * @param {Number} a length of the equatorial radius (the semi-major axis) in meters
<span class='line'>164</span>  * @param {Number} b length of the polar radius (the semi-minor axis) in meters
<span class='line'>165</span>  */</span><span class="WHIT">
<span class='line'>166</span> </span><span class="NAME">JSITM.Ellipsoid</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">b</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>167</span>     </span><span class="NAME">this.a</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">a</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>168</span>     </span><span class="NAME">this.b</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">b</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>169</span>     
<span class='line'>170</span>     </span><span class="COMM">// Compute eccentricity squared</span><span class="WHIT">
<span class='line'>171</span>     </span><span class="NAME">this.e2</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">b</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>172</span>     
<span class='line'>173</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>174</span> 
<span class='line'>175</span> </span><span class="COMM">/**************************************************************/</span><span class="WHIT">
<span class='line'>176</span> 
<span class='line'>177</span> </span><span class="COMM">/**
<span class='line'>178</span>  * Creates a new LatLng containing an angular representation of a cartesian Point on the surface of the Ellipsoid.
<span class='line'>179</span>  *
<span class='line'>180</span>  * @param {JSITM.Point} point
<span class='line'>181</span>  * @return {JSITM.LatLng}
<span class='line'>182</span>  */</span><span class="WHIT">
<span class='line'>183</span> </span><span class="NAME">JSITM.Ellipsoid.prototype.pointToLatLng</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">point</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>184</span> 
<span class='line'>185</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">RootXYSqr</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Math.sqrt</span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">point.x</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">point.y</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>186</span>     
<span class='line'>187</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">radlat1</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Math.atan2</span><span class="PUNC">(</span><span class="NAME">point.z</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">RootXYSqr</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">this.e2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>188</span>     
<span class='line'>189</span>     </span><span class="KEYW">do</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>190</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">V</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.a</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.sqrt</span><span class="PUNC">(</span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this.e2</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.sin</span><span class="PUNC">(</span><span class="NAME">radlat1</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>191</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">radlat2</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Math.atan2</span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">point.z</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this.e2</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">V</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.sin</span><span class="PUNC">(</span><span class="NAME">radlat1</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">RootXYSqr</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>192</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.abs</span><span class="PUNC">(</span><span class="NAME">radlat1</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">radlat2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NUMB">0.000000001</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>193</span>             </span><span class="NAME">radlat1</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">radlat2</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>194</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>195</span>         </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>196</span>             </span><span class="KEYW">break</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>197</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>198</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>199</span>     </span><span class="KEYW">while</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>200</span>     
<span class='line'>201</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">lat</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">radlat2</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">180</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">Math.PI</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>202</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">lng</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Math.atan2</span><span class="PUNC">(</span><span class="NAME">point.y</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">point.x</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">180</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">Math.PI</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>203</span>     
<span class='line'>204</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">JSITM.LatLng</span><span class="PUNC">(</span><span class="NAME">lat</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">lng</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>205</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>206</span> 
<span class='line'>207</span> </span><span class="COMM">/**
<span class='line'>208</span>  * Creates a new Point object containing a cartesian representation of an angular LatLng on the surface of the Ellipsoid.
<span class='line'>209</span>  *
<span class='line'>210</span>  * @param {JSITM.LatLng} latlng
<span class='line'>211</span>  * @return {JSITM.Point}
<span class='line'>212</span>  */</span><span class="WHIT">
<span class='line'>213</span> </span><span class="NAME">JSITM.Ellipsoid.prototype.latLngToPoint</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">latlng</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>214</span>     </span><span class="COMM">// Convert angle measures to radians</span><span class="WHIT">
<span class='line'>215</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">radlat</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">latlng.lat</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.PI</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">180</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>216</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">radlng</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">latlng.lng</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.PI</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">180</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>217</span>     
<span class='line'>218</span>     </span><span class="COMM">// Compute nu</span><span class="WHIT">
<span class='line'>219</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">V</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.a</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.sqrt</span><span class="PUNC">(</span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this.e2</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.sin</span><span class="PUNC">(</span><span class="NAME">radlat</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>220</span>     
<span class='line'>221</span>     </span><span class="COMM">// Compute XYZ</span><span class="WHIT">
<span class='line'>222</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">x</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">V</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">latlng.alt</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.cos</span><span class="PUNC">(</span><span class="NAME">radlat</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.cos</span><span class="PUNC">(</span><span class="NAME">radlng</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>223</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">y</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">V</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">latlng.alt</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.cos</span><span class="PUNC">(</span><span class="NAME">radlat</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.sin</span><span class="PUNC">(</span><span class="NAME">radlng</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>224</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">z</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">V</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">this.e2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">latlng.alt</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.sin</span><span class="PUNC">(</span><span class="NAME">radlat</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>225</span>     
<span class='line'>226</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">JSITM.Point</span><span class="PUNC">(</span><span class="NAME">x</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">y</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">z</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>227</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>228</span> 
<span class='line'>229</span> </span><span class="COMM">/**
<span class='line'>230</span>  * Cretaes a new TM (Transverse Mercator Projection).&lt;br>
<span class='line'>231</span>  * For more info see &lt;a href="http://en.wikipedia.org/wiki/Transverse_Mercator">http://en.wikipedia.org/wiki/Transverse_Mercator&lt;/a>
<span class='line'>232</span>  *
<span class='line'>233</span>  * @constructor
<span class='line'>234</span>  * @param {JSITM.Ellipsoid} reference ellipsoid
<span class='line'>235</span>  * @param {Number} e0 eastings of false origin in meters
<span class='line'>236</span>  * @param {Number} n0 northings of false origin in meters
<span class='line'>237</span>  * @param {Number} f0 central meridian scale factor
<span class='line'>238</span>  * @param {Number} lat0 latitude of false origin in decimal degrees.
<span class='line'>239</span>  * @param {Number} lng0 longitude of false origin in decimal degrees.
<span class='line'>240</span>  */</span><span class="WHIT">
<span class='line'>241</span> </span><span class="NAME">JSITM.TM</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">ellipsoid</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">e0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">n0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">f0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">lat0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">lng0</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>242</span>     </span><span class="COMM">//eastings (e0) and northings (n0) of false origin in meters; _</span><span class="WHIT">
<span class='line'>243</span>     </span><span class="COMM">//central meridian scale factor (f0) and _</span><span class="WHIT">
<span class='line'>244</span>     </span><span class="COMM">//latitude (lat0) and longitude (lng0) of false origin in decimal degrees.</span><span class="WHIT">
<span class='line'>245</span>     
<span class='line'>246</span>     </span><span class="NAME">this.ellipsoid</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">ellipsoid</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>247</span>     </span><span class="NAME">this.e0</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">e0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>248</span>     </span><span class="NAME">this.n0</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">n0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>249</span>     </span><span class="NAME">this.f0</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">f0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>250</span>     </span><span class="NAME">this.lat0</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">lat0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>251</span>     </span><span class="NAME">this.lng0</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">lng0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>252</span>     
<span class='line'>253</span>     </span><span class="NAME">this.radlat0</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">lat0</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.PI</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">180</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>254</span>     </span><span class="NAME">this.radlng0</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">lng0</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.PI</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">180</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>255</span>     
<span class='line'>256</span>     </span><span class="NAME">this.af0</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">ellipsoid.a</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">f0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>257</span>     </span><span class="NAME">this.bf0</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">ellipsoid.b</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">f0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>258</span>     </span><span class="NAME">this.e2</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">this.af0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">this.bf0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">this.af0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>259</span>     </span><span class="NAME">this.n</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this.af0</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">this.bf0</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this.af0</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">this.bf0</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>260</span>     </span><span class="NAME">this.n2</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.n</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">this.n</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="COMM">//for optimizing and clarity of Marc()</span><span class="WHIT">
<span class='line'>261</span>     </span><span class="NAME">this.n3</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.n2</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">this.n</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="COMM">//for optimizing and clarity of Marc()</span><span class="WHIT">
<span class='line'>262</span>     
<span class='line'>263</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>264</span> 
<span class='line'>265</span> </span><span class="COMM">/**
<span class='line'>266</span>  * Compute meridional arc
<span class='line'>267</span>  * @private
<span class='line'>268</span>  * @param {Number} radlat latitude of meridian in radians
<span class='line'>269</span>  * @return {Number}
<span class='line'>270</span>  */</span><span class="WHIT">
<span class='line'>271</span> </span><span class="NAME">JSITM.TM.prototype.Marc</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">radlat</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>272</span>     
<span class='line'>273</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="WHIT">
<span class='line'>274</span> 		</span><span class="NAME">this.bf0</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="WHIT">
<span class='line'>275</span> 			</span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">this.n</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NUMB">5</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">4</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">this.n2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NUMB">5</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">4</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">this.n3</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">radlat</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">this.radlat0</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> 
<span class='line'>276</span> 			</span><span class="PUNC">(</span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NUMB">3</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">this.n</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">3</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">this.n2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NUMB">21</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">8</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">this.n3</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.sin</span><span class="PUNC">(</span><span class="NAME">radlat</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">this.radlat0</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.cos</span><span class="PUNC">(</span><span class="NAME">radlat</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">this.radlat0</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> 
<span class='line'>277</span> 			</span><span class="PUNC">(</span><span class="PUNC">(</span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NUMB">15</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">8</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">this.n2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NUMB">15</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">8</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">this.n3</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.sin</span><span class="PUNC">(</span><span class="NUMB">2</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">radlat</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">this.radlat0</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.cos</span><span class="PUNC">(</span><span class="NUMB">2</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">radlat</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">this.radlat0</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> 
<span class='line'>278</span> 			</span><span class="PUNC">(</span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NUMB">35</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">24</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">this.n3</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.sin</span><span class="PUNC">(</span><span class="NUMB">3</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">radlat</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">this.radlat0</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.cos</span><span class="PUNC">(</span><span class="NUMB">3</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">radlat</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">this.radlat0</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>279</span> 		</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>280</span> 	</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>281</span> 		
<span class='line'>282</span> 
<span class='line'>283</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>284</span> 
<span class='line'>285</span> </span><span class="COMM">/**
<span class='line'>286</span>  * Returns the  initial value for Latitude in radians.
<span class='line'>287</span>  * @private
<span class='line'>288</span>  * @param {Number} y northings of point
<span class='line'>289</span>  * @return {Number}
<span class='line'>290</span>  */</span><span class="WHIT">
<span class='line'>291</span> </span><span class="NAME">JSITM.TM.prototype.InitialLat</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">y</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>292</span>   
<span class='line'>293</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">radlat1</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">y</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">this.n0</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">this.af0</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">this.radlat0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>294</span> 
<span class='line'>295</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">M</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.Marc</span><span class="PUNC">(</span><span class="NAME">radlat1</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>296</span>     
<span class='line'>297</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">radlat2</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">y</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">this.n0</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">M</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">this.af0</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">radlat1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>298</span>     
<span class='line'>299</span>     </span><span class="KEYW">while</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.abs</span><span class="PUNC">(</span><span class="NAME">y</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">this.n0</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">M</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NUMB">0.00001</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>300</span>         </span><span class="NAME">radlat2</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">y</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">this.n0</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">M</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">this.af0</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">radlat1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>301</span>         </span><span class="NAME">M</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.Marc</span><span class="PUNC">(</span><span class="NAME">radlat2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>302</span>         </span><span class="NAME">radlat1</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">radlat2</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>303</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>304</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">radlat2</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>305</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>306</span> 
<span class='line'>307</span> </span><span class="COMM">/**
<span class='line'>308</span>  * Un-project Transverse Mercator eastings and northings back to latitude and longtitude.
<span class='line'>309</span>  * 
<span class='line'>310</span>  * @param {JSITM.Point} point
<span class='line'>311</span>  * @return {JSITM.LatLng} latitude and longtitude on the refernced ellipsoid's surface
<span class='line'>312</span>  */</span><span class="WHIT">
<span class='line'>313</span> 
<span class='line'>314</span> </span><span class="NAME">JSITM.TM.prototype.unproject</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">point</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>315</span>     </span><span class="COMM">//</span><span class="WHIT">
<span class='line'>316</span>     </span><span class="COMM">//Input: - _</span><span class="WHIT">
<span class='line'>317</span>     
<span class='line'>318</span>     </span><span class="COMM">//Compute Et</span><span class="WHIT">
<span class='line'>319</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">Et</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">point.x</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">this.e0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>320</span>     
<span class='line'>321</span>     </span><span class="COMM">//Compute initial value for latitude (PHI) in radians</span><span class="WHIT">
<span class='line'>322</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">PHId</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.InitialLat</span><span class="PUNC">(</span><span class="NAME">point.y</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>323</span>     
<span class='line'>324</span>     </span><span class="COMM">//Compute nu, rho and eta2 using value for PHId</span><span class="WHIT">
<span class='line'>325</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">nu</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.af0</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.sqrt</span><span class="PUNC">(</span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this.e2</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.sin</span><span class="PUNC">(</span><span class="NAME">PHId</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>326</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rho</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">nu</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">this.e2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this.e2</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.sin</span><span class="PUNC">(</span><span class="NAME">PHId</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>327</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">eta2</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">nu</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">rho</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>328</span>     
<span class='line'>329</span>     </span><span class="COMM">//Compute Latitude</span><span class="WHIT">
<span class='line'>330</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">VII</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.tan</span><span class="PUNC">(</span><span class="NAME">PHId</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">2</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">rho</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">nu</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>331</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">VIII</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">Math.tan</span><span class="PUNC">(</span><span class="NAME">PHId</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">24</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">rho</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">nu</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">3</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">5</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">3</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.tan</span><span class="PUNC">(</span><span class="NAME">PHId</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">eta2</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">9</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">eta2</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.tan</span><span class="PUNC">(</span><span class="NAME">PHId</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>332</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">IX</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.tan</span><span class="PUNC">(</span><span class="NAME">PHId</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">720</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">rho</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">nu</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">5</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">61</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">90</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.tan</span><span class="PUNC">(</span><span class="NAME">PHId</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">45</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.tan</span><span class="PUNC">(</span><span class="NAME">PHId</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">4</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>333</span>     
<span class='line'>334</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">lat</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">180</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">Math.PI</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">PHId</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Et</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">VII</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Et</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">4</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">VIII</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Et</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">6</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">IX</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>335</span>     
<span class='line'>336</span>     </span><span class="COMM">//Compute Longitude</span><span class="WHIT">
<span class='line'>337</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">X</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.cos</span><span class="PUNC">(</span><span class="NAME">PHId</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">nu</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>338</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">XI</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.cos</span><span class="PUNC">(</span><span class="NAME">PHId</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">6</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">nu</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">3</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">nu</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">rho</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">2</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.tan</span><span class="PUNC">(</span><span class="NAME">PHId</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>339</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">XII</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.cos</span><span class="PUNC">(</span><span class="NAME">PHId</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">120</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">nu</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">5</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">5</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">28</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.tan</span><span class="PUNC">(</span><span class="NAME">PHId</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">24</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.tan</span><span class="PUNC">(</span><span class="NAME">PHId</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">4</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>340</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">XIIA</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.cos</span><span class="PUNC">(</span><span class="NAME">PHId</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">5040</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">nu</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">7</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">61</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">662</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.tan</span><span class="PUNC">(</span><span class="NAME">PHId</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">1320</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.tan</span><span class="PUNC">(</span><span class="NAME">PHId</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">4</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">720</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.tan</span><span class="PUNC">(</span><span class="NAME">PHId</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">6</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>341</span>     
<span class='line'>342</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">lng</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">180</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">Math.PI</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this.radlng0</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Et</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">X</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Et</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">3</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">XI</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Et</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">5</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">XII</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Et</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">7</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">XIIA</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>343</span>     
<span class='line'>344</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">latlng</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">JSITM.LatLng</span><span class="PUNC">(</span><span class="NAME">lat</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">lng</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>345</span>     
<span class='line'>346</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">latlng</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>347</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>348</span> 
<span class='line'>349</span> 
<span class='line'>350</span> </span><span class="COMM">/**
<span class='line'>351</span>  * Project Latitude and longitude to Transverse Mercator coordinates
<span class='line'>352</span>  * @param {JSITM.LatLng} latitude and longtitude  to convert
<span class='line'>353</span>  * @return {JSITM.Point} projected coordinates 
<span class='line'>354</span>  */</span><span class="WHIT">
<span class='line'>355</span> </span><span class="NAME">JSITM.TM.prototype.project</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">latlng</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>356</span>     </span><span class="COMM">// Convert angle measures to radians</span><span class="WHIT">
<span class='line'>357</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">RadPHI</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">latlng.lat</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.PI</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">180</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>358</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">RadLAM</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">latlng.lng</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.PI</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">180</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>359</span>     
<span class='line'>360</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">nu</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.af0</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.sqrt</span><span class="PUNC">(</span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this.e2</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.sin</span><span class="PUNC">(</span><span class="NAME">RadPHI</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>361</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">rho</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">nu</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">this.e2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this.e2</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.sin</span><span class="PUNC">(</span><span class="NAME">RadPHI</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>362</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">eta2</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">nu</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">rho</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>363</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">p</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">RadLAM</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">this.radlng0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>364</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">M</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.Marc</span><span class="PUNC">(</span><span class="NAME">RadPHI</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>365</span>     
<span class='line'>366</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">I</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">M</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">this.n0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>367</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">II</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">nu</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.sin</span><span class="PUNC">(</span><span class="NAME">RadPHI</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.cos</span><span class="PUNC">(</span><span class="NAME">RadPHI</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>368</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">III</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">nu</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">24</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.sin</span><span class="PUNC">(</span><span class="NAME">RadPHI</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.cos</span><span class="PUNC">(</span><span class="NAME">RadPHI</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">3</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">5</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.tan</span><span class="PUNC">(</span><span class="NAME">RadPHI</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">9</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">eta2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>369</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">IIIA</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">nu</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">720</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.sin</span><span class="PUNC">(</span><span class="NAME">RadPHI</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.cos</span><span class="PUNC">(</span><span class="NAME">RadPHI</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">5</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">61</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">58</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.tan</span><span class="PUNC">(</span><span class="NAME">RadPHI</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.tan</span><span class="PUNC">(</span><span class="NAME">RadPHI</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">4</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>370</span>     
<span class='line'>371</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">y</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">I</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">p</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">II</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">p</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">4</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">III</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">p</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">6</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">IIIA</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>372</span>     
<span class='line'>373</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">IV</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">nu</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.cos</span><span class="PUNC">(</span><span class="NAME">RadPHI</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>374</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">V</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">nu</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">6</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.cos</span><span class="PUNC">(</span><span class="NAME">RadPHI</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">3</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">nu</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">rho</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.tan</span><span class="PUNC">(</span><span class="NAME">RadPHI</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>375</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">VI</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">nu</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">120</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.cos</span><span class="PUNC">(</span><span class="NAME">RadPHI</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">5</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">5</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">18</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.tan</span><span class="PUNC">(</span><span class="NAME">RadPHI</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.tan</span><span class="PUNC">(</span><span class="NAME">RadPHI</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">4</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">14</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">eta2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">58</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">Math.tan</span><span class="PUNC">(</span><span class="NAME">RadPHI</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">eta2</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>376</span>     
<span class='line'>377</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">x</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.e0</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">p</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">IV</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">p</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">3</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">V</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NAME">p</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">5</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">VI</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>378</span>     
<span class='line'>379</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">JSITM.Point</span><span class="PUNC">(</span><span class="NAME">x</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">y</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>380</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>381</span> 
<span class='line'>382</span> </span><span class="COMM">/** Juicy part 1 ***************************************************************************/</span><span class="WHIT">
<span class='line'>383</span> 
<span class='line'>384</span> </span><span class="COMM">/**
<span class='line'>385</span>  * Ellipsoid for GRS80 (The refernce ellipsoid of ITM
<span class='line'>386</span>  * @see http://en.wikipedia.org/wiki/GRS80
<span class='line'>387</span>  * @type JSITM.Ellipsoid
<span class='line'>388</span>  */</span><span class="WHIT">
<span class='line'>389</span> </span><span class="NAME">JSITM.GRS80</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">JSITM.Ellipsoid</span><span class="PUNC">(</span><span class="NUMB">6378137</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">6356752.31414</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> 
<span class='line'>390</span> 
<span class='line'>391</span> </span><span class="COMM">/**
<span class='line'>392</span>  * Ellipsoid for WGS84 (Used by GPS)
<span class='line'>393</span>  * @see http://en.wikipedia.org/wiki/WGS80
<span class='line'>394</span>  * @type JSITM.Ellipsoid
<span class='line'>395</span>  */</span><span class="WHIT">
<span class='line'>396</span> </span><span class="NAME">JSITM.WGS84</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">JSITM.Ellipsoid</span><span class="PUNC">(</span><span class="NUMB">6378137</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">6356752.314245</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>397</span> 
<span class='line'>398</span> </span><span class="COMM">/**
<span class='line'>399</span>  * Simple Translation from GRS80 to WGS84
<span class='line'>400</span>  * @see http://spatialreference.org/ref/epsg/2039/
<span class='line'>401</span>  * @type JSITM.Translation
<span class='line'>402</span>  */</span><span class="WHIT">
<span class='line'>403</span> </span><span class="NAME">JSITM.GRS80toWGS84</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">JSITM.Translation</span><span class="PUNC">(</span><span class="PUNC">-</span><span class="NUMB">48</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">55</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">52</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> 
<span class='line'>404</span> 
<span class='line'>405</span> </span><span class="COMM">/**
<span class='line'>406</span>  * Translation back from WGS84 to GRS80
<span class='line'>407</span>  * @type JSITM.Translation
<span class='line'>408</span>  */</span><span class="WHIT">
<span class='line'>409</span> </span><span class="NAME">JSITM.WGS84toGRS80</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">JSITM.GRS80toWGS84.inverse</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>410</span> 
<span class='line'>411</span> </span><span class="COMM">/**
<span class='line'>412</span>  * ITM (Israel Transverse Mercator) Projection 
<span class='line'>413</span>  * @see http://en.wikipedia.org/wiki/Israeli_Transverse_Mercator
<span class='line'>414</span>  * @type JSITM.TM
<span class='line'>415</span>  */</span><span class="WHIT">
<span class='line'>416</span> </span><span class="NAME">JSITM.ITM</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">JSITM.TM</span><span class="PUNC">(</span><span class="NAME">JSITM.GRS80</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">219529.58400</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">626907.38999</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">1.000006700000000</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">31.734394</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">35.204517</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>417</span> 
<span class='line'>418</span> 
<span class='line'>419</span> </span><span class="COMM">/** Juicy part 2 ***************************************************************************/</span><span class="WHIT">
<span class='line'>420</span> 
<span class='line'>421</span> </span><span class="COMM">/**
<span class='line'>422</span>  * Converts a point to an ITM reference.
<span class='line'>423</span>  * 
<span class='line'>424</span>  * @example 
<span class='line'>425</span>  *   JSITM.point2ItmRef(new JSITM.Point(200, 500)); // prints "200000500000"
<span class='line'>426</span>  *   JSITM.point2ItmRef(new JSITM.Point(200, 500), 3); // prints "200500"
<span class='line'>427</span>  * @param {JSITM.Point} point
<span class='line'>428</span>  * @param {Number} precision 3=km, 4=100 meter, 5=decameter 6=meter.  optional, default is 6,
<span class='line'>429</span>  * @return {String}
<span class='line'>430</span>  */</span><span class="WHIT">
<span class='line'>431</span> </span><span class="NAME">JSITM.point2ItmRef</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">point</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">precision</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>432</span> 
<span class='line'>433</span> 	</span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">zeropad</span><span class="PUNC">(</span><span class="NAME">num</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">len</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>434</span> 	    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">str</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">String</span><span class="PUNC">(</span><span class="NAME">num</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>435</span> 	    </span><span class="KEYW">while</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">str.length</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">len</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>436</span> 	        </span><span class="NAME">str</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">'0'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">str</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>437</span> 	    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>438</span> 	    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">str</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>439</span> 	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>440</span> 	
<span class='line'>441</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">p</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">precision</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NUMB">6</span><span class="PUNC">;</span><span class="WHIT"> 
<span class='line'>442</span> 
<span class='line'>443</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">p</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NUMB">3</span><span class="PUNC">)</span><span class="WHIT"> 
<span class='line'>444</span>         </span><span class="NAME">p</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">3</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>445</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">p</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NUMB">6</span><span class="PUNC">)</span><span class="WHIT"> 
<span class='line'>446</span>         </span><span class="NAME">p</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">6</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>447</span>     
<span class='line'>448</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">div</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NUMB">10</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NUMB">6</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">p</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>449</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">east</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Math.round</span><span class="PUNC">(</span><span class="NAME">point.x</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">div</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>450</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">north</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Math.round</span><span class="PUNC">(</span><span class="NAME">point.y</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">div</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>451</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">zeropad</span><span class="PUNC">(</span><span class="NAME">east</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">p</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">' '</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">zeropad</span><span class="PUNC">(</span><span class="NAME">north</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">p</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>452</span> 	
<span class='line'>453</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>454</span> 
<span class='line'>455</span> </span><span class="COMM">/**
<span class='line'>456</span>  * Parses an ITM reference and returns a Point object.&lt;p>
<span class='line'>457</span>  * throws an exception for invalid refernce!&lt;p>
<span class='line'>458</span>  * &lt;p>
<span class='line'>459</span>  * @example valid inputs:
<span class='line'>460</span>  *  200500
<span class='line'>461</span>  *  20005000
<span class='line'>462</span>  *  2000000500000
<span class='line'>463</span>  *  130:540
<span class='line'>464</span>  *  131550:44000
<span class='line'>465</span>  *  131 400
<span class='line'>466</span>  *  210222 432111
<span class='line'>467</span>  * 
<span class='line'>468</span>  * @param {String} s
<span class='line'>469</span>  * @return {JSITM.Point}
<span class='line'>470</span>  */</span><span class="WHIT">
<span class='line'>471</span> </span><span class="NAME">JSITM.itmRef2Point</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>472</span>     
<span class='line'>473</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">precision</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>474</span>     
<span class='line'>475</span>     </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">precision</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">6</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">precision</span><span class="WHIT"> </span><span class="PUNC">>=</span><span class="WHIT"> </span><span class="NUMB">3</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">precision</span><span class="PUNC">--</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>476</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">pattern</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">RegExp</span><span class="PUNC">(</span><span class="STRN">"^(\\d{"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">precision</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"})\\s*:?\\s*(\\d{"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">precision</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"})$"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"i"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>477</span>         </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">ref</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.match</span><span class="PUNC">(</span><span class="NAME">pattern</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>478</span>         </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">ref</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>479</span>             </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">precision</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>480</span>                 </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">mult</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Math.pow</span><span class="PUNC">(</span><span class="NUMB">10</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">6</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">precision</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>481</span>                 </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">x</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parseInt</span><span class="PUNC">(</span><span class="NAME">ref</span><span class="PUNC">[</span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">10</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">mult</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>482</span>                 </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">y</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parseInt</span><span class="PUNC">(</span><span class="NAME">ref</span><span class="PUNC">[</span><span class="NUMB">2</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">10</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">mult</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>483</span>                 </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">JSITM.Point</span><span class="PUNC">(</span><span class="NAME">x</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">y</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>484</span>             </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>485</span>         </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>486</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>487</span>     
<span class='line'>488</span> 	</span><span class="KEYW">throw</span><span class="WHIT"> </span><span class="STRN">"Could not parse reference"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>489</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>490</span> 
<span class='line'>491</span> 
<span class='line'>492</span> </span><span class="COMM">/** Juicy part 3 ***************************************************************************/</span><span class="WHIT">
<span class='line'>493</span> 
<span class='line'>494</span> </span><span class="COMM">/**
<span class='line'>495</span>  * Converts a Point on ITM to a LatLng on GPS 
<span class='line'>496</span>  * @param {JSITM.Point} point
<span class='line'>497</span>  * @return {JSITM.LatLng}
<span class='line'>498</span>  */</span><span class="WHIT">
<span class='line'>499</span> </span><span class="NAME">JSITM.itm2gps</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">point</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>500</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">latlng</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.ITM.unproject</span><span class="PUNC">(</span><span class="NAME">point</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="COMM">//however, latlng is still on GRS80!</span><span class="WHIT">
<span class='line'>501</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">latlng.convertGrid</span><span class="PUNC">(</span><span class="NAME">this.GRS80</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this.WGS84</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this.GRS80toWGS84</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>502</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>503</span> 
<span class='line'>504</span> </span><span class="COMM">/**
<span class='line'>505</span>  * Converts a LatLng on GPS to a Point on ITM
<span class='line'>506</span>  * @param {JSITM.LatLng} latlng
<span class='line'>507</span>  * @return {JSITM.Point}
<span class='line'>508</span>  */</span><span class="WHIT">
<span class='line'>509</span> 
<span class='line'>510</span> </span><span class="NAME">JSITM.gps2itm</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">latlng</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>511</span>     </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">wgs84</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">latlng.convertGrid</span><span class="PUNC">(</span><span class="NAME">this.WGS84</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this.GRS80</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this.WGS84toGRS80</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="COMM">//first convert to GRS80</span><span class="WHIT">
<span class='line'>512</span>     </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this.ITM.project</span><span class="PUNC">(</span><span class="NAME">wgs84</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>513</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>514</span> 
<span class='line'>515</span> </span><span class="COMM">/** Juicy part 4 ***************************************************************************/</span><span class="WHIT">
<span class='line'>516</span> 
<span class='line'>517</span> </span><span class="COMM">/**
<span class='line'>518</span>  * Converts an ITM grid refernece in 6, 8, 10 or 12 digits to a GPS angular Point instace
<span class='line'>519</span>  * @param {String} s
<span class='line'>520</span>  * @return {JSITM.Point}
<span class='line'>521</span>  */</span><span class="WHIT">
<span class='line'>522</span> </span><span class="NAME">JSITM.itmRef2gps</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>523</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">point</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.itmRef2Point</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>524</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this.itm2gps</span><span class="PUNC">(</span><span class="NAME">point</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>525</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>526</span> 
<span class='line'>527</span> </span><span class="COMM">/**
<span class='line'>528</span>  * Converts an ITM grid refernece in 6, 8, 10 or 12 digits to a GPS angular reference
<span class='line'>529</span>  * @param {String} s
<span class='line'>530</span>  * @return {String}
<span class='line'>531</span>  */</span><span class="WHIT">
<span class='line'>532</span> </span><span class="NAME">JSITM.itmRef2gpsRef</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>533</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this.itmRef2gps</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">toString</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>534</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>535</span> 
<span class='line'>536</span> </span><span class="COMM">/**
<span class='line'>537</span>  * Converts a GPS angular reference to an ITM LatLng instance
<span class='line'>538</span>  * @param {String} s
<span class='line'>539</span>  * @return {JSITM.LatLng} 
<span class='line'>540</span>  */</span><span class="WHIT">
<span class='line'>541</span> 
<span class='line'>542</span> </span><span class="NAME">JSITM.gpsRef2itm</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>543</span> 	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">latlng</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.latlngFromString</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>544</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this.gps2itm</span><span class="PUNC">(</span><span class="NAME">latlng</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>545</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>546</span> 
<span class='line'>547</span> </span><span class="COMM">/**
<span class='line'>548</span>  * Converts a GPS angular reference to an ITM grid refernece in 6, 8, 10 or 12 digits
<span class='line'>549</span>  * @param {String} s
<span class='line'>550</span>  * @param {Number} precision 3=km, 4=100 meter, 5=decameter 6=meter. Optional.  Default value is 6=meter
<span class='line'>551</span>  * @return {String} 
<span class='line'>552</span>  */</span><span class="WHIT">
<span class='line'>553</span> 
<span class='line'>554</span> </span><span class="NAME">JSITM.gpsRef2itmRef</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">precision</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>555</span> 	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this.point2ItmRef</span><span class="PUNC">(</span><span class="NAME">this.gpsRef2itm</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">precision</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NUMB">6</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>556</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>557</span> 
<span class='line'>558</span> </span></pre></body></html>